/*
 * Copyright (c) 2002-2025 Gargoyle Software Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.htmlunit.html;

import org.htmlunit.WebDriverTestCase;
import org.htmlunit.junit.annotation.Alerts;
import org.junit.jupiter.api.Test;

/**
 * Tests for {@link HtmlTemplate}.
 *
 * @author Ronald Brill
 */
public class HtmlTemplateTest extends WebDriverTestCase {

    /**
     * @throws Exception if the test fails
     */
    @Test
    @Alerts({"2", "null", "null"})
    public void noChilds() throws Exception {
        final String html = DOCTYPE_HTML
            + "<html><head>\n"
            + "<script>\n"
            + LOG_TITLE_FUNCTION
            + "  function test() {\n"
            + "    log(document.querySelectorAll('form input[type=radio][name=\"rad\"]').length);\n"
            + "    log(document.querySelector('form input[type=radio][name=\"rad\"][value=\"3\"]'));\n"
            + "    log(document.querySelector('form input[type=radio][name=\"rad\"][value=\"4\"]'));\n"
            + "  }\n"
            + "</script>\n"
            + "</head>\n"
            + "<body onload='test()'>\n"
            + "<form>\n"
            + "  <input type='radio' id='radio1' name='rad' value='1' checked/>\n"
            + "  <input type='radio' name='rad' value='2'/>\n"
            + "  <template>\n"
            + "    <input type='radio' name='rad' value='3' checked/>\n"
            + "    <input type='radio' name='rad' value='4'/>\n"
            + "  </template>\n"
            + "</body></html>";

        loadPageVerifyTitle2(html);
    }

    /**
     * @throws Exception if the test fails
     */
    @Test
    @Alerts("true")
    public void ignoreContent() throws Exception {
        final String html = DOCTYPE_HTML
            + "<html><head>\n"
            + "<script>\n"
            + LOG_TITLE_FUNCTION
            + "  function test() {\n"
            + "    log(document.getElementById('radio1').checked);\n"
            + "  }\n"
            + "</script>\n"
            + "</head>\n"
            + "<body onload='test()'>\n"
            + "<form>\n"
            + "  <input type='radio' id='radio1' name='rad' value='1' checked/>\n"
            + "  <input type='radio' name='rad' value='2'/>\n"
            + "  <template>\n"
            + "    <input type='radio' name='rad' value='3' checked/>\n"
            + "    <input type='radio' name='rad' value='4'/>\n"
            + "  </template>\n"
            + "</body></html>";

        loadPageVerifyTitle2(html);
    }
}
